const Web3 = require('web3');
const HDWalletProvider = require('truffle-hdwallet-provider');

class BinanceKlineUpdater {
    constructor(config) {
        this.web3 = new Web3(new HDWalletProvider(config.mnemonic, config.url));
        this.contract = new this.web3.eth.Contract(config.abi, config.address);
        this.init()
    }
    async init(){
        let a = await this.contract.methods.TradeCount().call();
        let a = await this.contract.methods.getRewardBalance(2).send();
        console.log(a)
    }
}


let config = {
    url: 'https://rinkeby.infura.io/v3/ef8cd40931114dabb4032fc0314a4d55',
    mnemonic: "winner weird snack cry today penalty isolate joy secret turn jealous wagon",
    abi: [
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "isPause",
                    "type": "bool"
                }
            ],
            "name": "PauseEvent",
            "type": "event"
        },
        {
            "constant": false,
            "inputs": [
                {
                    "name": "rootUser",
                    "type": "address"
                },
                {
                    "name": "grandPrizePoolUser",
                    "type": "address"
                },
                {
                    "name": "dataUser",
                    "type": "address"
                }
            ],
            "name": "changeConfig",
            "outputs": [],
            "payable": false,
            "stateMutability": "nonpayable",
            "type": "function"
        },
        {
            "constant": false,
            "inputs": [
                {
                    "name": "isBuy",
                    "type": "bool"
                },
                {
                    "name": "parentAddress",
                    "type": "address"
                }
            ],
            "name": "CreateOrder",
            "outputs": [],
            "payable": true,
            "stateMutability": "payable",
            "type": "function"
        },
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "userAddress",
                    "type": "address"
                },
                {
                    "indexed": false,
                    "name": "amount",
                    "type": "uint256"
                }
            ],
            "name": "PayUserEvent",
            "type": "event"
        },
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "parentIds",
                    "type": "uint256"
                },
                {
                    "indexed": false,
                    "name": "amount",
                    "type": "uint256"
                }
            ],
            "name": "PayParentEvent",
            "type": "event"
        },
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "amountUser",
                    "type": "uint256"
                }
            ],
            "name": "PayWinnerEvent",
            "type": "event"
        },
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "id",
                    "type": "uint256"
                },
                {
                    "indexed": false,
                    "name": "openPrice",
                    "type": "uint256"
                },
                {
                    "indexed": false,
                    "name": "closePrice",
                    "type": "uint256"
                }
            ],
            "name": "UpdateRoundEvent",
            "type": "event"
        },
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "isBuy",
                    "type": "bool"
                },
                {
                    "indexed": false,
                    "name": "parentAddress",
                    "type": "address"
                }
            ],
            "name": "CreateOrderEvent",
            "type": "event"
        },
        {
            "anonymous": false,
            "inputs": [],
            "name": "PayBackEvent",
            "type": "event"
        },
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "amount",
                    "type": "uint256"
                }
            ],
            "name": "PayRootUserEvent",
            "type": "event"
        },
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "userAddress",
                    "type": "address"
                }
            ],
            "name": "UserCreatedEvent",
            "type": "event"
        },
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": false,
                    "name": "userAddress",
                    "type": "address"
                },
                {
                    "indexed": false,
                    "name": "parentAddress",
                    "type": "address"
                }
            ],
            "name": "UserCreatedEvent",
            "type": "event"
        },
        {
            "constant": false,
            "inputs": [
                {
                    "name": "id",
                    "type": "uint256"
                }
            ],
            "name": "getRewardBalance",
            "outputs": [],
            "payable": false,
            "stateMutability": "nonpayable",
            "type": "function"
        },
        {
            "constant": false,
            "inputs": [
                {
                    "name": "isPause",
                    "type": "bool"
                }
            ],
            "name": "Pause",
            "outputs": [],
            "payable": false,
            "stateMutability": "nonpayable",
            "type": "function"
        },
        {
            "constant": false,
            "inputs": [
                {
                    "name": "id",
                    "type": "uint256"
                },
                {
                    "name": "openPrice",
                    "type": "uint256"
                },
                {
                    "name": "closePrice",
                    "type": "uint256"
                },
                {
                    "name": "isResultUpdateSuccess",
                    "type": "bool"
                }
            ],
            "name": "UpdateRound",
            "outputs": [],
            "payable": false,
            "stateMutability": "nonpayable",
            "type": "function"
        },
        {
            "inputs": [
                {
                    "name": "period",
                    "type": "uint256"
                },
                {
                    "name": "minAmount",
                    "type": "uint256"
                },
                {
                    "name": "dataUser",
                    "type": "address"
                },
                {
                    "name": "grandPrizePoolUser",
                    "type": "address"
                }
            ],
            "payable": true,
            "stateMutability": "payable",
            "type": "constructor"
        },
        {
            "constant": false,
            "inputs": [
                {
                    "name": "id",
                    "type": "uint256"
                }
            ],
            "name": "withDraw",
            "outputs": [],
            "payable": false,
            "stateMutability": "nonpayable",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "DataUser",
            "outputs": [
                {
                    "name": "",
                    "type": "address"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "userId",
                    "type": "uint256"
                },
                {
                    "name": "directChildId",
                    "type": "uint256"
                }
            ],
            "name": "DirectChildId_From_UserId",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "GrandPrizePoolUser",
            "outputs": [
                {
                    "name": "",
                    "type": "address"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "IsPause",
            "outputs": [
                {
                    "name": "",
                    "type": "bool"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "LastUpdateRoundId",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "MinTradeAmount",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "Period",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "RootUser",
            "outputs": [
                {
                    "name": "",
                    "type": "address"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "RoundCount",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "name": "RoundId_MapBy_StartTime",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "name": "Rounds",
            "outputs": [
                {
                    "name": "startTime",
                    "type": "uint256"
                },
                {
                    "name": "openPrice",
                    "type": "uint256"
                },
                {
                    "name": "closePrice",
                    "type": "uint256"
                },
                {
                    "name": "buyVol",
                    "type": "uint256"
                },
                {
                    "name": "buyCount",
                    "type": "uint256"
                },
                {
                    "name": "sellVol",
                    "type": "uint256"
                },
                {
                    "name": "sellCount",
                    "type": "uint256"
                },
                {
                    "name": "isCreate",
                    "type": "bool"
                },
                {
                    "name": "resultUpdateTime",
                    "type": "uint256"
                },
                {
                    "name": "isResultUpdateSuccess",
                    "type": "bool"
                },
                {
                    "name": "_trade_Count",
                    "type": "uint256"
                },
                {
                    "name": "grandPrizePoolStartBalance",
                    "type": "uint256"
                },
                {
                    "name": "grandPrizePoolAmount",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "TradeCount",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "userId",
                    "type": "uint256"
                },
                {
                    "name": "tradeId",
                    "type": "uint256"
                }
            ],
            "name": "TradeId_From_UserId",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "id",
                    "type": "uint256"
                }
            ],
            "name": "TradeResult",
            "outputs": [
                {
                    "name": "",
                    "type": "uint8"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "name": "Trades",
            "outputs": [
                {
                    "name": "_round_id",
                    "type": "uint256"
                },
                {
                    "name": "orderCreateTime",
                    "type": "uint256"
                },
                {
                    "name": "isBuy",
                    "type": "bool"
                },
                {
                    "name": "isCreate",
                    "type": "bool"
                },
                {
                    "name": "amount",
                    "type": "uint256"
                },
                {
                    "name": "_user_id",
                    "type": "uint256"
                },
                {
                    "name": "isWithDraw",
                    "type": "bool"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "UserAmount",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [],
            "name": "UserCount",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "",
                    "type": "address"
                }
            ],
            "name": "UserId_MapBy_Address",
            "outputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "name": "Users",
            "outputs": [
                {
                    "name": "userAddress",
                    "type": "address"
                },
                {
                    "name": "parent_User_Id",
                    "type": "uint256"
                },
                {
                    "name": "directChild_User_Count",
                    "type": "uint256"
                },
                {
                    "name": "isCreated",
                    "type": "bool"
                },
                {
                    "name": "_trade_Count",
                    "type": "uint256"
                },
                {
                    "name": "tradeAmount",
                    "type": "uint256"
                },
                {
                    "name": "rewardBlance",
                    "type": "uint256"
                },
                {
                    "name": "allRewardBlance",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        }
    ],
    address: "0x4f7a7bc9723ef430a54302ea5ba64329fcb9e3b1"
};


async function Sleep(ms) {
    await new Promise((resolve, reject) => {
        setTimeout(resolve, ms);
    });
}
// let BKU = new BinanceKlineUpdater(config);
// BKU.run();

new BinanceKlineUpdater(config);